<?php
class security extends spController
{
	function init(){
		if ($_SESSION['last_key']) {
			$this->jump(spUrl('main', 'home'));			
		} else {
			$o = new SaeTOAuth( WB_AKEY , WB_SKEY  );
			if( $_SERVER['SERVER_PORT'] != 80 ) $port = ':'.$_SERVER['SERVER_PORT'];
			$proto=is_https()?'https://':'http://';
			$keys = $o->getRequestToken();
			$aurl = $o->getAuthorizeURL( $keys['oauth_token'] ,false , $proto .$_SERVER['HTTP_HOST'].'/index.php?c=main&a=callback');
			$_SESSION['keys'] = $keys;
			//$this->aurl = $aurl; 
			//$this->display('main/index.html');
			Header('Location:'.$aurl);
		}
	}

	function callback() {
		$o = new SaeTOAuth( WB_AKEY , WB_SKEY , $_SESSION['keys']['oauth_token'] , $_SESSION['keys']['oauth_token_secret']  );
		$last_key = $o->getAccessToken(  $_REQUEST['oauth_verifier'] ) ;
		$_SESSION['last_key'] = $last_key;
		$this->jump(spUrl('main', 'home'));
	}

}